package com.lcf.system.controller;

import com.lcf.common.utils.UserUtils;
import com.lcf.framework.annotation.PermissionCheck;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.tenant.SysTenantDTO;
import com.lcf.system.dto.tenant.SysTenantEditDTO;
import com.lcf.system.query.tenant.SysTenantPageQuery;
import com.lcf.system.service.SysTenantService;
import com.lcf.system.vo.tenant.SysTenantVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lcf.framework.enums.PermissionEnum.*;

/**
 * 租户(SysTenant)表控制层
 *
 * @author lcf
 * @since 2025-03-02 23:00:13
 */
@Tag(name = "租户")
@RestController
@RequestMapping("sysTenant")
public class SysTenantController {
    @Resource
    private SysTenantService sysTenantService;

    /**
     * 新增租户
     */
    @Operation(summary = "新增租户")
    @PermissionCheck(SYS_TENANT_ADD)
    @PostMapping
    public void add(@Validated @RequestBody SysTenantDTO dto) {
        sysTenantService.add(dto);
    }

    /**
     * 修改我的租户
     */
    @Operation(summary = "修改我的租户")
    @PermissionCheck(SYS_TENANT_EDIT)
    @PatchMapping
    public void edit(@Validated @RequestBody SysTenantEditDTO dto) {
        sysTenantService.edit(dto);
    }

    /**
     * 查询租户分页列表
     */
    @Operation(summary = "查询租户分页列表")
    @PermissionCheck(SYS_TENANT_PAGE)
    @GetMapping("page")
    public PageVO<SysTenantVO> page(SysTenantPageQuery query) {
        return sysTenantService.page(query);
    }

    /**
     * 查询租户详情
     */
    @Operation(summary = "查询租户详情")
    @PermissionCheck(SYS_TENANT_DETAIL)
    @GetMapping("detail")
    public SysTenantVO detail(long tenantId) {
        return sysTenantService.detail(tenantId);
    }

    /**
     * 查询我的租户详情
     */
    @Operation(summary = "查询我的租户详情")
    @GetMapping("myDetail")
    public SysTenantVO myDetail() {
        return sysTenantService.detail(UserUtils.getTenantId());
    }
}


